package cn.mju.tankfighterbackend.config.websocket;


import cn.mju.tankfighterbackend.service.game.GameServer;
import jakarta.websocket.OnMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;



@Configuration
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    GameServer gameServer;
    @Autowired
    HandShakeInterceptor handShake;
    @OnMessage
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(gameServer,"game").addInterceptors(handShake).setAllowedOrigins("*");

    }
    //一些基础配置
    @Bean
    public ServletServerContainerFactoryBean createWebSocketContainer() {
        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
        container.setMaxTextMessageBufferSize(8192);
        container.setMaxBinaryMessageBufferSize(8192);

        return container;
    }
}
